/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#if !defined(AFX_PGLERRORBAR_H__5B6246E0_B96A_4B3E_A1B9_CD9234DC997A__INCLUDED_)
#define AFX_PGLERRORBAR_H__5B6246E0_B96A_4B3E_A1B9_CD9234DC997A__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <pgl/core/PGLLine2D.h>

/*! \brief A error bar graph

This object represents error bar. It has 2 main options:
	- Vertical or horizontal error bars, ( #SetVertical )
	- Absolute or relative error values, ( #SetAbsolute )

It inherits from all the characteristics of a CPGLLine2D.

\par Data



  \ingroup PGLLineGroup
*/
class PGLCORE_EXT_CLASS CPGLErrorBar : public CPGLLine2D
{
PGL_DECLARE_DYNCREATE(CPGLErrorBar);
public: 
    //! \name Constructor
    //@{
    //! default constructor
    CPGLErrorBar(const CPGLColor& _FrontColor = CPGLColor(0,0,0,1), const CPGLColor& _FillColor = CPGLColor(0.3f,0.3f,0.3f,1));
    //! copy constructor
    CPGLErrorBar(const CPGLErrorBar& l):m_pErrorUp(CPGLDataPtr()), m_pErrorDown(CPGLDataPtr()) {*this = l;};
    //! assignement constructor
    CPGLErrorBar& operator=(const CPGLErrorBar& l);
    //! desctructor
	virtual ~CPGLErrorBar();
	//@}

	//! \name Extent
	//@{
	//! Extent computation
    //virtual void GetUnionExtent(gfxinterface::CGfxInterface& gfx, CPGLRectD& rExtent);
    ///virtual function to override in derived classes
    virtual void UpdateExtent(gfxinterface::CGfxInterface& gfx);
	//@}

	//! \name Error bar specifications
	//@{
	//! the error type, default is absolute
	void SetAbsolute( bool bAbsolute )					{	m_bAbsolute = bAbsolute;};
	//! returns the current error type, default is absolute
	bool IsAbsolute() const								{	return m_bAbsolute;};
	//! sets true for vertical error bar, false for horizontal
	void SetVertical( bool bVertical)					{	m_bVertical = bVertical;};
	//! returns true if vertical
	bool IsVertical() const								{	return m_bVertical;};
	//! sets the bar with in pixels, default is 10
	void SetBarWidth( double dPixels)					{	m_dErrorBarWidth=__max(0,dPixels);};
	//! returns the bar width, default = 10
	double GetBarWidth() const							{	return m_dErrorBarWidth;};
	//! No base line
	void SetShowLine( bool yes)							{	m_bShowBaseLine =yes;};
	//! returns true if base line is shown
	bool IsShowLine() const								{	return m_bShowBaseLine;};
	//@}

	//! \name Error Data
	//@{
	/*! Setting the data

	Sets pErrorUp and pErrorDown as the vector of data. Previous data, if any, is deleted. pErrorUp and pErrorDown must have been allocated on the heap.
	*/
	void SetErrorDatas(CPGLDataPtr pErrorUp, CPGLDataPtr pErrorDown);
	/*! Setting data as vectors of double

	This is a helper function that uses the generic form of SetDatas and spares the user the creation of CPGLData objects.
	\param bMakeOwnCopy if true, a copy of the data is stored, otherwize only the reference is stored (default is true)
	*/
    void SetErrorDatas(const std::vector<double>& vErrorUp, const std::vector<double>& vErrorDown, bool bMakeCopy = true);
	/*! Setting data as vectors of double

	This is a helper function that uses the generic form of SetDatas and spares the user the creation of CPGLData objects.
	\param bMakeOwnCopy if true, a copy of the data is stored, otherwize only the reference is stored (default is true)
	*/
    void SetErrorDatas(const std::vector<float>& vErrorUp, const std::vector<float>& vErrorDown, bool bMakeCopy = true);
	/*! Setting data as vectors of double

	This is a helper function that uses the generic form of SetDatas and spares the user the creation of CPGLData objects.
	\param bMakeOwnCopy if true, a copy of the data is stored, otherwize only the reference is stored (default is true)
	*/
    void SetErrorDatas(const std::vector<int>& vErrorUp, const std::vector<int>& vErrorDown, bool bMakeCopy = true);
	/*! Setting data as vectors of double

	This is a helper function that uses the generic form of SetDatas and spares the user the creation of CPGLData objects.
	\param bMakeOwnCopy if true, a copy of the data is stored, otherwize only the reference is stored (default is true)
	*/
    void SetErrorDatas(const std::vector<BYTE>& vErrorUp, const std::vector<BYTE>& vErrorDown, bool bMakeCopy = true);
	//! Delete current error data
	void ClearErrorData();
	//@}

	//! \name Scripting methods
	//@{
	//! property enumeration
	enum EErrorBarProp
	{
		ErrorBarPropUnknow,
		ErrorBarPropVertical,
		ErrorBarPropAbsolute,
		ErrorBarPropBaseLine,
		ErrorBarPropBarWidth
	};
	PGL_DECLARE_SCRIPTING(ErrorBar);
	//@}

	//! \name Serialization and debugging
	//@{
	//! Saving setttings to XML
	void SerializeXML(CPGLArchive& ar);
    //! Debuggin functions
    #ifdef _DEBUG
        virtual void Dump( CDumpContext& dc ) const;
        virtual void AssertValid() const;    // Override
    #endif
    //@}

protected:
	//! \name Virtual functions override
	//@{
	virtual void PlotLineStripGfx(gfxinterface::CGfxInterface& gfx);
	//@}
protected:
	//! \name Attributes
	//@{
	CPGLDataPtr m_pErrorUp;
	CPGLDataPtr m_pErrorDown;
	bool m_bAbsolute;
	bool m_bVertical;
	bool m_bShowBaseLine;
	double m_dErrorBarWidth;
	//@}
};

PGL_DECLARE_SMARTPTR( CPGLErrorBar );

#endif // !defined(AFX_PGLERRORBAR_H__5B6246E0_B96A_4B3E_A1B9_CD9234DC997A__INCLUDED_)
